home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / c_course.zip / SUMSQRES.C < prev    next >
Text File  |  1989-12-30  |  896b  |  32 lines

  1. int sum; /* This is a global variable */
  2.  
  3. main()
  4. {
  5. int index;
  6.  
  7.    header();        /* This calls the function named header */
  8.    for (index = 1;index <= 7;index++)
  9.      square(index); /* This calls the square function */
  10.    ending();        /* This calls the ending function */
  11. }
  12.  
  13. header()        /* This is the function named header */
  14. {
  15.    sum = 0;     /* Initialize the variable "sum" */
  16.    printf("This is the header for the square program\n\n");
  17. }
  18.  
  19. square(number)   /* This is the square function */
  20. int number;
  21. {
  22. int numsq;
  23.  
  24.    numsq = number * number;  /* This produces the square */
  25.    sum += numsq;
  26.    printf("The square of %d is %d\n",number,numsq);
  27. }
  28.  
  29. ending()   /* This is the ending function */
  30. {
  31.    printf("\nThe sum of the squares is %d\n",sum);
  32. }